package cn.iocoder.yudao.module.product.controller.admin.calculationmodel;

import cn.iocoder.yudao.module.product.controller.admin.calculationmodel.vo.ProcessModelCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.calculationmodel.vo.ProcessModelRespVO;
import cn.iocoder.yudao.module.product.controller.admin.calculationmodel.vo.ProcessModelUpdateReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.module.product.service.calculationmodel.ProcessModelService;

@Tag(name =  "管理后台 - 工序-模型关联")
@RestController
@RequestMapping("/product/process-model")
@Validated
public class ProcessModelController {

    @Resource
    private ProcessModelService processModelService;

    @PostMapping("/create")
    @Operation(summary = "创建工序-模型关联")
    @PreAuthorize("@ss.hasPermission('product:process-model:create')")
    public CommonResult<Long> createProcessModel(@Valid @RequestBody ProcessModelCreateReqVO createReqVO) {
        return success(processModelService.createProcessModel(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新工序-模型关联")
    @PreAuthorize("@ss.hasPermission('product:process-model:update')")
    public CommonResult<Boolean> updateProcessModel(@Valid @RequestBody ProcessModelUpdateReqVO updateReqVO) {
        processModelService.updateProcessModel(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除工序-模型关联")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('product:process-model:delete')")
    public CommonResult<Boolean> deleteProcessModel(@RequestParam("id") Long id) {
        processModelService.deleteProcessModel(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得工序-模型关联")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('product:process-model:query')")
    public CommonResult<ProcessModelRespVO> getProcessModel(@RequestParam("id") Long id) {
        ProcessModelRespVO processModelRespVO = processModelService.getProcessModel(id);
        return success(processModelRespVO);
    }

}
